﻿package app.view.components.sections.expo.max 
{
	import app.model.RemoteProxy;
	import app.model.types.SectionType;
	import app.model.vo.SectionVO;
	import app.view.components.buttons.GlamurBtnBase;
	import app.view.components.header.HeadMarkerBase;
	import app.view.components.sections.LabeledSectionBase;
	import app.view.events.UIEvent;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/**
	 * 1.1.2.1 ВИДЕО-ПРЕЗЕНТАЦИЯ ПАВИЛЬОНА
	 * firsoff maxim, snzflash.com, tel: +79222345364, skype: maxim.firsoff
	 */
	public class ExpoPavilionVideoPresentMBase extends LabeledSectionBase
	{
		// app.view.components.sections.expo.max.ExpoPavilionVideoPresentMBase
		
		public var text:TextField;
		public var btn_MapRoute:GlamurBtnBase;
		public var sostavExpozit_Btn:GlamurBtnBase;
		
		public  var vidik:VideoBoxPresentInterview;
		
		
		
		public function ExpoPavilionVideoPresentMBase() 
		{
			super();
		}
		
		override protected function init():void
		{
			super.init();
			
			text.wordWrap = true;
			text.multiline = true;
		}
		
		private function setEvents():void
		{
			btn_MapRoute.addEventListener(MouseEvent.CLICK, onClickMapRouteBtn);
			sostavExpozit_Btn.addEventListener(MouseEvent.CLICK, onCLickSostavExpo);
			
		}
		
		private function removeEvents():void
		{
			btn_MapRoute.removeEventListener(MouseEvent.CLICK, onClickMapRouteBtn);
			sostavExpozit_Btn.removeEventListener(MouseEvent.CLICK, onCLickSostavExpo);
			
		}
		
		override public function onDestroy():void 
		{
			// чистим что тут есть и вызываем супера
			removeEvents();
			
			btn_MapRoute.destroy();
			sostavExpozit_Btn.destroy();
			
			vidik.destroy();
			
			super.onDestroy();
		};
		
		override public function get data():Object { return _data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			setParamHead(HeadMarkerBase.BGD_RED);
			
			btn_MapRoute.setLang(_data.lang);
			sostavExpozit_Btn.setLang(_data.lang);
			
			
			var textVideo:String = '';
			var urlVideo:String = '';
			
			for each(var object:* in _data.data.video_extends)
			{
				//trace('8888');
				urlVideo = (object.flv[1].flv_path != '') ? RemoteProxy.DOMEN + object.flv[1].flv_path : null;
				textVideo 	= object.text[1];
			}
			
			trace('++++', urlVideo);
			
			vidik.autoPlay = false;
			vidik.source = urlVideo;
			
			//vidik.pause();
			
			text.htmlText = textVideo;
			
			
			setEvents();
		};
		
		/**
		 * переходим в карту и маршрут
		 * @param	e
		 */
		private function onClickMapRouteBtn(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_EXPO_MAP_AND_ROUTE;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
		
		/**
		 * переходим в состав экспозиции
		 * @param	e
		 */
		private function onCLickSostavExpo(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_EXPO_STRUCTURE_EXPOSITIONS;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
			
		}
		
	}

}